package cst.a903dss.zyfypt_903dss.fragment;


import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import cst.a903dss.zyfypt_903dss.PagerSlidingTabStrip;
import cst.a903dss.zyfypt_903dss.R;

/**
 * A simple {@link Fragment3} subclass.
 */
public class Fragment3 extends Fragment {
    //private TextView tvinfo;
    private View view=null;
    private Context context;
    private PagerSlidingTabStrip pagerSliding;
    private ViewPager viewpager;
    private Fragment31 fragment31;
    private Fragment32 fragment32;
    private DisplayMetrics dm;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable  ViewGroup container,
                             @Nullable  Bundle savedInstanceState) {
        context=getActivity();
        View view = inflater.inflate(R.layout.fragment3,container,false);
        init(view);
        return view;
    }
    private void init(View view) {
        dm = getResources().getDisplayMetrics();
        ViewPager viewpager = (ViewPager) view.findViewById(R.id.wPager);
        viewpager.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
        pagerSliding = (PagerSlidingTabStrip) view.findViewById(R.id.pagerslidingtabstrip);
        pagerSliding.setViewPager(viewpager);
        setpagerstyle();
    }
    private void setpagerstyle(){
        pagerSliding.setShouldExpand(true);
        pagerSliding.setDividerColor(Color.TRANSPARENT);
        pagerSliding.setUnderlineHeight((int) TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP,1,dm));
        pagerSliding.setIndicatorHeight((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,4,dm));
        pagerSliding.setTextSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,16,dm));
        pagerSliding.setSelectedTextColor(Color.parseColor("#45c01a"));
        pagerSliding.setSelectedTextColor(Color.parseColor("#45c01a"));
        pagerSliding.setTabBackground(0);
    }
    private class MyPagerAdapter extends FragmentStatePagerAdapter {
        private String[] titles={"最新","专题"};

        public MyPagerAdapter(FragmentManager childFragmentManager) {
            super(childFragmentManager);
        }


        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
        @Override
        public int getCount() {
            return titles.length;
        }
        @Override
        public Fragment getItem(int position) {
            switch (position)
            {
                case 0:
                    if (null==fragment31){
                        fragment31=new Fragment31();
                    }
                    return fragment31;
                case 1:
                    if (null==fragment32){
                        fragment32=new Fragment32();
                    }
                    return fragment32;
                default:return null;
            }
        }
    }
}
